import { ipcMain } from "electron";
import { clientIndexService } from "~/service";

ipcMain.handle("/api/client/index/list", async (_e, payload) => {
  const { id } = payload;
  return clientIndexService.listIndex(id);
});

ipcMain.handle("/api/client/index/get", async (_e, payload) => {
  const { id, index } = payload;
  return clientIndexService.getIndex(id, index);
});

ipcMain.handle("/api/client/index/create", async (_e, payload) => {
  const { id, data } = payload;
  return clientIndexService.createIndex(id, data);
});

ipcMain.handle("/api/client/index/update", async (_e, payload) => {
  const { id, index, data } = payload;
  return clientIndexService.updateIndex(id, index, data);
});

ipcMain.handle("/api/client/index/delete", async (_e, payload) => {
  const { id, indexIds } = payload;
  return clientIndexService.deleteBatchIndex(id, indexIds);
});

ipcMain.handle("/api/client/index/alias/add", async (_e, payload) => {
  const { id, index, alias } = payload;
  return clientIndexService.addAlias(id, index, alias);
});

ipcMain.handle("/api/client/index/alias/remove", async (_e, payload) => {
  const { id, index, alias } = payload;
  return clientIndexService.removeAlias(id, index, alias);
});
